public class Solution2016 {
    public int maximumDifference(int[] nums) {
        int ans=Integer.MIN_VALUE;
        int min=nums[0];
        for (int i=1;i<nums.length;i++){
            ans=Math.max(ans,nums[i]-min);
            min=Math.min(min,nums[i]);
        }
        return ans>0?ans:-1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2016().maximumDifference(new int[]{7,1,5,4}));
    }
}
